Skip to content

[OpenVINO backend] Support numpy.logaddexp #21522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

samthakur587
Copy link
Contributor

@samthakur587 samthakur587 commented Jul 27, 2025

details: in this pr i have added logaddexp support for openvino backend

cc, @gbaned could you please review ?

Copy link

google-cla bot commented Jul 27, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @samthakur587, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

I've added support for the logaddexp function to the OpenVINO backend. This change enables the backend to correctly handle operations involving logaddexp, which was previously unsupported, by providing a robust and numerically stable implementation.

Highlights

  • OpenVINO Backend Extension: I've implemented the logaddexp function within the keras/src/backend/openvino/numpy.py file. This involves using OpenVINO operations (maximum, subtract, abs, negative, exp, log1p, add) to provide a numerically stable computation of log(exp(x1) + exp(x2)).
  • Test Suite Integration: I've removed logaddexp from the excluded_concrete_tests.txt file for both NumpyDtypeTest and NumpyOneInputOpsCorrectnessTest. This indicates that the logaddexp operation is now expected to pass its corresponding tests in the OpenVINO backend.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the logaddexp operation to the OpenVINO backend, which is a great addition. The implementation correctly uses a numerically stable formula. I have one suggestion to improve the code's readability by making it more concise.

Comment on lines 1029 to 1034
max_val = ov_opset.maximum(x1, x2).output(0)
abs_diff = ov_opset.abs(ov_opset.subtract(x1, x2).output(0)).output(0)
neg_abs_diff = ov_opset.negative(abs_diff).output(0)
exp_neg_abs = ov_opset.exp(neg_abs_diff).output(0)
log1p_exp = ov_opset.log1p(exp_neg_abs).output(0)
result = ov_opset.add(max_val, log1p_exp).output(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The implementation can be made more concise and readable by removing the redundant .output(0) calls. The OpenVINO ops can directly accept Node objects as inputs, and the .output(0) is only necessary when you need to explicitly get the output tensor, for example, before returning it or wrapping it in OpenVINOKerasTensor.

Suggested change
max_val = ov_opset.maximum(x1, x2).output(0)
abs_diff = ov_opset.abs(ov_opset.subtract(x1, x2).output(0)).output(0)
neg_abs_diff = ov_opset.negative(abs_diff).output(0)
exp_neg_abs = ov_opset.exp(neg_abs_diff).output(0)
log1p_exp = ov_opset.log1p(exp_neg_abs).output(0)
result = ov_opset.add(max_val, log1p_exp).output(0)
max_val = ov_opset.maximum(x1, x2)
abs_diff = ov_opset.abs(ov_opset.subtract(x1, x2))
neg_abs_diff = ov_opset.negative(abs_diff)
exp_neg_abs = ov_opset.exp(neg_abs_diff)
log1p_exp = ov_opset.log1p(exp_neg_abs)
result = ov_opset.add(max_val, log1p_exp).output(0)

@samthakur587 samthakur587 changed the title feat: Logaddexp to openvino backend [OpenVINO backend] Support numpy.logaddexp Jul 27, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jul 27, 2025

Codecov Report

❌ Patch coverage is 93.93939% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.74%. Comparing base (5d50953) to head (9c85bd1).

Files with missing lines Patch % Lines
keras/src/backend/openvino/numpy.py 93.93% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #21522   +/-   ##
=======================================
  Coverage   82.73%   82.74%           
=======================================
  Files         567      567           
  Lines       56464    56497   +33     
  Branches     8825     8830    +5     
=======================================
+ Hits        46718    46749   +31     
  Misses       7582     7582           
- Partials     2164     2166    +2     
Flag Coverage Δ
keras 82.55% <93.93%> (+<0.01%) ⬆️
keras-jax 63.77% <0.00%> (-0.04%) ⬇️
keras-numpy 58.26% <0.00%> (-0.04%) ⬇️
keras-openvino 34.67% <93.93%> (+0.03%) ⬆️
keras-tensorflow 64.21% <0.00%> (-0.04%) ⬇️
keras-torch 63.83% <0.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hertschuh
Copy link
Collaborator

@samthakur587 , can you rebase to merge changes to excluded_concrete_tests.txt? Then I can merge. Thanks!

@samthakur587
Copy link
Contributor Author

@hertschuh done !

@hertschuh
Copy link
Collaborator

@rkazants

Can you review and decide between this one and #21043 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Assigned Reviewer
Development

Successfully merging this pull request may close these issues.

4 participants